<?

class bf_sync {

	public static function begin($filename, $do_wait = false) {
		if ($fp = fopen($filename, 'a')) {
			$flags = ($do_wait ? LOCK_EX : LOCK_EX | LOCK_NB);
			if (!flock($fp, $flags)) {
				exit(0);
			}
			return $fp;
		} else {
			exit(0);
		}
		return null;
	}

	public static function end($fp, $do_halt = true) {
		@flock($fp, LOCK_UN);
		fclose($fp);
		if ($do_halt) {
			exit(0);
		}
	}
}

?>